import {
  NEW_TAB
}
from '../mutation-types'

const state = {
  tableNum: 0,
  curSeclected: 0,
  proItem: '产品管理',
  newTab: '',
  tabList: [{
    'title': '产品管理',
    'delShow': false,
    'show': false,
    'active': true,
    'id': +new Date(),
    'components': 'ProductProDefault',
    'text': 'infor0'
  }],
}

const mutations = {
  DEFAULT_PRODUCT_TAB(state) {
    state.tabList = [{
      'title': '产品管理',
      'delShow': false,
      'show': false,
      'active': true,
      'id': +new Date(),
      'components': 'ProductProDefault',
      'text': 'infor0'
    }]
    state.curSeclected = 0;
    state.tableNum = 0;
  },
  NEW_PRODUCT_TAB(state, tableLabel) {
    state.tableNum++;
    var name = '';
    var newTab = {
      'title': tableLabel.title,
      'delShow': true,
      'show': true,
      'active': true,
      'id': +new Date(),
      'components': tableLabel.components,
      'text': 'infor' + state.tableNum,
      'dataId': tableLabel.dataId,
      'dataSn': tableLabel.dataSn,
    };
    state.curSeclected = state.tableNum;

    state.tabList.push(newTab);
  },
  TOGGle_PRO_COMPONENT_BTN(state, componentIndex) { //切换 改变最新的索引值
    state.curSeclected = componentIndex;
  },
  // 删除
  DELETE_PRO_BTN(state, index) {
    state.tabList.splice(index, 1);
    state.curSeclected = 0;
    state.tableNum--; //因为删除一个要让状态中总的个数也减一     =》在新增时，state.curSeclected = state.tableNum;  后一个变成了前一个
  }
}
export default {
  state,
  mutations
}
